/** ###################################################################
**     Filename  : Events.C
**     Project   : Project
**     Processor : MCF51CN128CLK
**     Beantype  : Events
**     Version   : Driver 01.02
**     Compiler  : CodeWarrior ColdFireV1 C Compiler
**     Date/Time : 09/09/2009, 10:49 a.m.
**     Abstract  :
**         This is user's event module.
**         Put your event handler code here.
**     Settings  :
**     Contents  :
**         No public methods
**
** ###################################################################*/
/* MODULE Events */

#include "Cpu.h"
#include "Events.h"
#include "MDC.h"

/* User includes (#include below this line is not maintained by Processor Expert) */

/*
** ===================================================================
**     Event       :  AS1_OnError (module Events)
**
**     From bean   :  AS1 [AsynchroSerial]
**     Description :
**         This event is called when a channel error (not the error
**         returned by a given method) occurs. The errors can be
**         read using <GetError> method.
**         The event is available only when the <Interrupt
**         service/event> property is enabled.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
void  AS1_OnError(void)
{
  /* Write your code here ... */
}

/*
** ===================================================================
**     Event       :  AS1_OnRxChar (module Events)
**
**     From bean   :  AS1 [AsynchroSerial]
**     Description :
**         This event is called after a correct character is
**         received.
**         The event is available only when the <Interrupt
**         service/event> property is enabled and either the
**         <Receiver> property is enabled or the <SCI output mode>
**         property (if supported) is set to Single-wire mode.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
void  AS1_OnRxChar(void)
{
  AS1_TComData iProximal;
  AS1_TComData iMedial;
  AS1_TComData iDistal;
  AS1_TComData ch;
  AS1_TComData state;

  AS1_TComData sTexto[]= "Recive datos      ";
  word wTexto = 4;
  //AS1_SendBlock(sTexto,sizeof(sTexto),&wTexto);

  //Read received character and send it if no error is detected
  if(AS1_RecvChar(&ch) == ERR_OK)
    
  // cuando llege una solicitud de get, entonces se llama a las funciones:

  //de acuerdo al dato solicitado, se envian los tres angulos                  
  // implementar un switch case
  switch (ch)
  {
    case 'T':
      {
        MDC_GetThumbAngle( &iProximal, &iMedial, &iDistal);
        AS1_SendChar(ch);
        AS1_SendChar(iProximal);
        AS1_SendChar(iMedial);
        AS1_SendChar(iDistal);
      }break;
    case 'I':
      {
        MDC_GetIndexFingerAngle( &iProximal, &iMedial, &iDistal );      
        AS1_SendChar(ch);
        AS1_SendChar(iProximal);
        AS1_SendChar(iMedial);
        AS1_SendChar(iDistal);
      }break;
    case 'M':
      {
        MDC_GetMiddleFingerAngle( &iProximal, &iMedial, &iDistal);
        
        AS1_SendChar(ch);
        AS1_SendChar(iProximal);
        AS1_SendChar(iMedial);
        AS1_SendChar(iDistal);
      }break;
    case 'S':
      {
       MDC_GetHandState(&state);
       AS1_SendChar(state);
      }break;
      case 'R':
      {
        MDC_ResetHandState();
      }break;  
      
    }
}

/*
** ===================================================================
**     Event       :  AS1_OnTxChar (module Events)
**
**     From bean   :  AS1 [AsynchroSerial]
**     Description :
**         This event is called after a character is transmitted.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
void  AS1_OnTxChar(void)
{
  /* Write your code here ... */
}

/*
** ===================================================================
**     Event       :  AS1_OnFreeTxBuf (module Events)
**
**     From bean   :  AS1 [AsynchroSerial]
**     Description :
**         This event is called after the last character in output
**         buffer is transmitted.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
void  AS1_OnFreeTxBuf(void)
{
  /* Write your code here ... */
}

/*
** ===================================================================
**     Event       :  AD1_OnEnd (module Events)
**
**     From bean   :  AD1 [ADC]
**     Description :
**         This event is called after the measurement (which consists
**         of <1 or more conversions>) is/are finished.
**         The event is available only when the <Interrupt
**         service/event> property is enabled.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
void AD1_OnEnd(void)
{
  
}


/* END Events */

/*
** ###################################################################
**
**     This file was created by Processor Expert 3.06 [04.26]
**     for the Freescale ColdFireV1 series of microcontrollers.
**
** ###################################################################
*/
